import { createRouter, createWebHistory,createWebHashHistory } from 'vue-router'


const history = createWebHashHistory()

const routes = [
	{
		path: '/:catchAll(.*)',
		redirect: '/home',
	},
	{
		path: '/home',
		name: 'home',
		component: () => import('@/views/home/Home.vue'),
	},
	{
		path: '/product',
		name: 'product',
		component: () => import('@/views/product/Product.vue'),
	},
	{
		path: '/news',
		name: 'news',
		component: () => import('@/views/news/News.vue'),
	},
	{
		path: '/news/detail',
		name: 'newsDetail',
		component: () => import('@/views/news/Detail.vue'),
	},
	{
		path: '/about',
		name: 'about',
		component: () => import('@/views/about/About.vue'),
	},
	{
		path: '/course',
		name: 'course',
		component: () => import('@/views/course/Course.vue'),
	},
	{
		path: '/course/detail',
		name: 'courseDetail',
		component: () => import('@/views/course/Detail.vue'),
	},
	{
		path: '/community',
		name: 'community',
		component: () => import('@/views/community/Community.vue'),
	},
	{
		path: '/community/detail',
		name: 'communityDetail',
		component: () => import('@/views/community/Detail.vue'),
	}
]
const router = createRouter({
	history,
	routes,
	scrollBehavior(to, from, savedPosition) {
		if (savedPosition) {
			//如果有保存的滚动位置，测直接返回
			return savedPosition;
		}
		else{
			//否则返回顶部
			return {top: 0}
		}	
	}
})

// router.beforeEach((to, from, next) => {
//   if (to.name === 'login') {
//     next()
//     return
//   }
//   // 登录验证
//   if (!Cookies.get('accessToken')) {
//     next({
//       path: '/login'
//     })
//     return
//   }
//   next()
// })

export default router